package com.wms.service.impl;

import com.wms.dao.CustomerDao;
import com.wms.model.Customer;
import com.wms.model.PageBean;
import com.wms.service.CustomerService;
import com.wms.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @author This
 * @version 1.0
 * @date 2019/7/18 14:22
 */
@Service
@Transactional
public class CustomerServiceImpl extends BaseServiceImpl<Customer> implements CustomerService {

    @Autowired
    private CustomerDao dao;

    @Override
    public void pageQuery(PageBean<Customer> pb) {
        try {
            dao.pageQuery(pb);
        } catch (Exception e) {
        }
    }

    @Override
    public boolean add(Customer customer) {
        List<Customer> list = dao.findByCondition("cusName=? and cusPhone=? ", customer.getCusName(), customer.getCusPhone());
        if (CommonUtils.isEmpty(list)) {
            dao.save(customer);
            return true;
        }
        return false;
    }

    @Override
    public void delete(Customer customer) {
        dao.delete(customer);
    }

    @Override
    public void edit(Customer customer) {
        dao.update(customer);
    }

    @Override
    public Customer find(Serializable id) {
        return dao.find(id);
    }

    @Override
    public void deleteAll(String ids) {
        ids = " id in ( " + ids + " )";
        dao.deleteAll(ids);
    }
}
